<template>
  <div class="container1">
    <div class="info-box">
      <van-image
        round
        fit="cover"
        width="64"
        height="64"
        :src="userInfo.photo"
      />
      <h2 class="name">
        {{ userInfo.name }}
        <br />
        <van-tag type="primary" color="#ccc" text-color="#3296fa">{{
          userInfo.birthday
        }}</van-tag>
      </h2>
    </div>
    <div class="layout">
      <van-row>
        <van-col span="8"
          ><van-icon name="newspaper-o" color="#7af" />我的作品</van-col
        >
        <van-col span="8"
          ><van-icon name="star-o" color="#f00" />我的收藏</van-col
        >
        <van-col span="8"
          ><van-icon name="tosend" color="#fa0" />我的历史</van-col
        >
      </van-row>
    </div>
    <van-cell-group class="cell">
      <van-cell title="编辑资料" icon="edit" to="/edit" is-link />
      <van-cell title="小邓同学" icon="chat-o" to="/student" is-link />
      <van-cell title="系统设置" icon="setting-o" is-link />
      <van-cell
        title="退出登录"
        icon="warning-o"
        is-link
        @click="logoutClick"
      />
    </van-cell-group>
  </div>
</template>

<script>
import { getUserInfo } from './user.js'
import { removeToken } from '../../utils/token.js'
export default {
  name: 'user',
  data () {
    return {
      userInfo: {}
    }
  },
  created () {
    getUserInfo()
      .then(res => {
        console.log(res)
        this.userInfo = res.data.data
        this.$store.commit('setUserInfo', res.data.data)
      })
      .catch(() => {
        this.$router.push({ path: '/login' })
      })
  },
  methods: {
    logoutClick () {
      this.$dialog
        .confirm({ title: '提示', message: '确定退出？' })
        .then(() => {
          removeToken()
          this.userInfo = {}
          this.$router.push({ path: '/home' })
        })
        .catch(() => {})
    }
  }
}
</script>

<style scoped lang="less">
.container1 {
  .info-box {
    background-color: #3296fa;
    display: flex;
    align-items: center;
    height: 100px;
    padding-left: 15px;
    .name {
      font-size: 18px;
      color: white;
      margin-left: 15px;
      font-size: 400;
    }
  }
  .layout {
    font-size: 12px;
    text-align: center;
    background-color: #fff;
    padding: 15px 0;
    .van-icon {
      display: block;
      font-size: 24px;
      padding-bottom: 5px;
    }
  }
}
</style>
